﻿using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace Demos.Convexhull
{
    /// <summary>
    /// Interaction logic for ContenedorPuntosUserControl.xaml
    /// </summary>
    public partial class ContenedorPuntosUserControl : UserControl
    {

        public ObservableCollection<ElementoVisual> ContenidoVisual
        {
            get { return (ObservableCollection<ElementoVisual>)GetValue(ContenidoVisualProperty); }
            set { SetValue(ContenidoVisualProperty, value); }
        }

        // Using a DependencyProperty as the backing store for ContenidoVisual.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty ContenidoVisualProperty =
            DependencyProperty.Register("ContenidoVisual", typeof(ObservableCollection<ElementoVisual>), typeof(ContenedorPuntosUserControl), new UIPropertyMetadata(null));



        public ContenedorPuntosUserControl()
        {
            InitializeComponent();
        }

        private void CanvasMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            (DataContext as ViewModel).X = e.GetPosition(grid).X;
            (DataContext as ViewModel).Y = e.GetPosition(grid).Y;
            (DataContext as ViewModel).CrearPuntoCommand.Execute(this);
        }

        private void UserControlSizeChanged(object sender, SizeChangedEventArgs e)
        {
            (DataContext as ViewModel).AnchoVisor = grid.ActualWidth;
            (DataContext as ViewModel).AltoVisor = grid.ActualHeight;
            (DataContext as ViewModel).RedimensionarCommand.Execute(this);
        }
    }
}
